﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverChart.Configuration;
using System.Collections.Generic;
using SilverChart.Core.Configuration;

namespace SilverChart.LineChart {
    public class LineChartConfigurationWrapper {
        private Element Data;

        public const String ITEM_NAME_SHOWDOT = "show_dot";
        public Boolean DefaultShowDot = true;
        private ValueItemHelper<Boolean> showDot;

        public const String ITEM_NAME_DOTFILL = "dot_fill";
        public readonly static Color DefaultDotFillColor = Colors.Blue;
        private BrushValueItemHelper dotFill;

        public const String ITEM_NAME_DOTSTROKE = "dot_stroke_color";
        public const Brush DefaultDotStroke = null;
        private BrushValueItemHelper dotStroke;

        public const String ITEM_NAME_DOTRADIUS = "dot_radius";
        public const Double DefaultDotRadius = 3.5d;
        private SimpleValueItemHelper<Double> dotRadius;

        public const String ITEM_NAME_DOTSTROKETHICKNESS = "dot_stroke_thickness";
        public const Double DefaultDotStrokeThickness = 2.0d;
        private SimpleValueItemHelper<Double> dotStrokeThichness;

        public const String ITEM_NAME_LINESTROKE = "line_stroke_color";
        public readonly static Color DefaultLineStrokeColor = Colors.Blue;
        private BrushValueItemHelper lineStroke;

        public const String ITEM_NAME_LINESTROKETHICKNESS = "line_stroke_thickness";
        public const Double DefaultLineStrokeThickness = 4.0d;
        private SimpleValueItemHelper<Double> lineStrockThickness;

        public LineChartConfigurationWrapper(Element data) {
            Data = data;
            showDot = new SimpleValueItemHelper<Boolean>(Data, ITEM_NAME_SHOWDOT, DefaultShowDot);
            dotFill = new BrushValueItemHelper(Data, ITEM_NAME_DOTFILL, DefaultDotFillColor);
            dotRadius = new SimpleValueItemHelper<Double>(Data, ITEM_NAME_DOTRADIUS, DefaultDotRadius);
            dotStroke = new BrushValueItemHelper(Data, ITEM_NAME_DOTSTROKE, DefaultDotStroke);
            dotStrokeThichness = new SimpleValueItemHelper<Double>(Data, ITEM_NAME_DOTSTROKETHICKNESS, DefaultDotStrokeThickness);

            lineStroke = new BrushValueItemHelper(Data, ITEM_NAME_LINESTROKE, DefaultLineStrokeColor);
            lineStrockThickness = new SimpleValueItemHelper<Double>(Data, ITEM_NAME_LINESTROKETHICKNESS, DefaultLineStrokeThickness);
        }

        public Boolean ShowTip { get { return Data.ShowTip; } }
        public Boolean ShowDot { get { return showDot.Value; } }
        public IList<Double> Values { get { return Data.Values; } }
        public String LegendName { get { return Data.LegendName; } }

        public Brush DotFill { get { return dotFill.Value; } }
        public Double DotRadius { get { return dotRadius.Value; } }
        public Brush DotStroke { get { return dotStroke.Value; } }
        public Double DotStrokeThickness { get { return dotStrokeThichness.Value; } }

        public Brush LineStroke { get { return lineStroke.Value; } }
        public Double LineStrokeThickness { get { return lineStrockThickness.Value; } }

        public const String ShowDotFill = "ShowDot_Fill";
        public const String ShowDotStroke = "ShowDot_Stroke";
        public readonly static Brush EmptyDotStroke = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
        public readonly static Brush EmptyDotFill = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
        public Path Dot {
            get {
                Path dotPath = new Path();
                dotPath.StrokeThickness = DotStrokeThickness;
                //dotPath.Cursor = Cursors.Hand;

                EllipseGeometry ellipse = new EllipseGeometry();
                ellipse.RadiusX = ellipse.RadiusY = DotRadius;
                dotPath.Data = ellipse;

                Brush showDot_Fill = DotFill;
                Brush showDot_Stroke = DotStroke == null ? Configurations.Instance.BackgroundColor : DotStroke;
                dotPath.Resources.Add(ShowDotFill, showDot_Fill);
                dotPath.Resources.Add(ShowDotStroke, showDot_Stroke);
                return dotPath;
            }
        }

        public Path ChartLine {
            get {
                Path linePath = new Path();
                linePath.Stroke = LineStroke;
                linePath.StrokeThickness = LineStrokeThickness;
                return linePath;
            }
        }
    }
}
